//
//  DomesticViewController.swift
//  TravelNotes
//
//  Created by 千锋 on 16/8/18.
//  Copyright © 2016年 胡光健. All rights reserved.
//

import UIKit

class DomesticViewController: UIViewController,UICollectionViewDelegateFlowLayout,UICollectionViewDelegate, UICollectionViewDataSource {

    var collectionView: UICollectionView?
    
    var dataArray = NSMutableArray()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        createUI()
        getData()
    }
    
    func getData() {
        let manager = AFHTTPSessionManager()
        
        manager.GET("http://chanyouji.com/api/destinations.json", parameters: nil, success: { (dataTask: NSURLSessionDataTask?, resp: AnyObject?) -> Void in
            
            
            
            print(resp)
            
            }) { (dataTask: NSURLSessionDataTask?, error: ErrorType?) -> Void in
                print(error)
        }
    }

    func createUI() {
        let flowlayout = UICollectionViewFlowLayout()
        flowlayout.scrollDirection = .Vertical
        self.collectionView = UICollectionView(frame: CGRectMake(10, 10, screenWidth - 20, screenHeight), collectionViewLayout: flowlayout)
        
        collectionView?.delegate = self
        collectionView?.dataSource = self
        collectionView?.backgroundColor = UIColor.whiteColor()
        
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataArray.count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("", forIndexPath: indexPath)
        
        
        return cell
    }
    
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        return CGSizeMake((screenWidth - 30) / 2, 150)
    }
}
